<?php
/**
 * Created by PhpStorm.
 * User: 17274
 * Date: 2018/3/27
 * Time: 21:06
 */
namespace app\admin\model;

use think\Model;
use think\Validate;

class LogsModel extends  Model
{
    protected $table = 'yui_logs';
    /*
     * rule
     * 验证data
     * @params $data
     * 新增和修改时验证
     * */
    public function validate_model(){

    }

    /*
     * 操作者获取器
     * op_id
     * 驼峰式规则
     * */
    public function getOpIdAttr($value){
        $admins=(new AdminModel)->listAll()->toArray();
        foreach ($admins as $admin)
            if ($admin['id']==$value)
                return $admin['name'];
    }

    /*
     * 新增日志
     * */
    public static function add($log){
        $model=new LogsModel();
        $model->save($log);
    }

    /*
     * 日志列表
     * */
    public function listAll(){
        return $this->order('created_at desc')->select();
    }


}